from django.db import models
import django.utils.timezone as timezone

# Create your models here.
class Subject(models.Model):
    id = models.AutoField(primary_key=True)
    title = models.TextField(null=True)
    answer = models.TextField(null=True)
    company = models.CharField(max_length=60,null=True)
    address = models.CharField(max_length=300,null=True)
    student_id = models.CharField(max_length=50, null=True)
    student_name = models.CharField(max_length=100, null=True)
    subject = models.CharField(max_length=20, null=True)
    classroom = models.CharField(max_length=200, null=True)
    collection_num = models.IntegerField(default=0, null=True)
    click_num = models.IntegerField(default=0, null=True)
    add_time = models.DateTimeField(max_length=30, auto_now_add=True)
    # 设置外键
    teacher = models.ForeignKey(to='User', on_delete=models.SET_NULL, null=True)
    state = models.IntegerField(default=0)

    class Meta:
        ordering = ('-add_time', )
# 存储收藏内容
class Collection(models.Model):
    id = models.AutoField(primary_key=True)
    subject_id = models.ForeignKey(Subject, related_name='collection', null=True, on_delete=models.SET_NULL)
    collection_time = models.CharField(max_length=50, null=True)
    student_id = models.IntegerField(null=True)

# 评论内容
class Comment(models.Model):
    id = models.AutoField(primary_key=True)
    subject_id = models.ForeignKey(Subject, related_name='comment', null=True, on_delete=models.SET_NULL)
    content = models.TextField(null=True)
    comment_time = models.CharField(max_length=50, null=True)
    student_id = models.IntegerField()

# 定义用户列表存储教师信息
class User(models.Model):
    id = models.AutoField(primary_key=True)
    account = models.CharField(max_length=20, unique=True)
    pwd = models.CharField(max_length=20, null=True)
    name = models.CharField(max_length=50, default='讲师')
    type = models.CharField(max_length=10, default='讲师')
    photo = models.CharField(max_length=200, null=True)

# 定义角色表存储教师身份角色
class SubjectRole(models.Model):
    id = models.AutoField(primary_key=True)
    role = models.CharField(max_length=50)
    teas = models.ManyToManyField(User, related_name='roles')






